﻿using System;
using System.Windows.Markup;
using System.Windows.Media;

namespace Eniux.Framework.Extensions.MarkupExtensions
{
   /// <summary>
    /// ImageSource 标记扩展类
   /// </summary>
   public class ImageSourceExtension:MarkupExtension
    {
        #region 私有变量

        private ImageSource source;
        
        #endregion

        #region 构造

        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="imageRelativePath">图片相对路径</param>
        public ImageSourceExtension(string imageRelativePath)
        {
            source = (ImageSource)new ImageSourceConverter().ConvertFromString("pack://siteOfOrigin:,,,/" + imageRelativePath);
        } 

        #endregion

        #region 重写方法

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return source;
        } 

        #endregion
    }
}
